package view;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import model.CiiBay;

/**
 * Zorgt voor het afhandelen van categorie.
 * @author Yoeri
 * @author Marvin
 * @since 31-05-2010
 *
 */
@SuppressWarnings("serial")
public class CategorieView extends JPanel {
	
	private JButton voegToe;
	private JTextField naamCategorie;
	private CiiBay ciiBay;
	private JLabel label;
	
	public CategorieView(CiiBay cb) {
		this.ciiBay = cb;
		setLayout(new GridBagLayout());
		naamCategorie = new JTextField(15);
		naamCategorie.setDocument(new MaxAantalKarakters(25));
		voegToe = new JButton("Toevoegen");
		voegToe.setBackground(Color.ORANGE);
		naamCategorie.setSize(100, 20);
		label = new JLabel("Categorie naam:  ");
		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.VERTICAL;
        c.gridx = 0;
        c.gridy = 0;
        add(label, c);
        c.gridx = 1;
        add(naamCategorie,c);
        c.gridy = 1;
        add(voegToe,c);
        this.setBackground(Color.ORANGE);
		
        voegToe.addActionListener(new toeVoegKnopHandler());  
	}
	
	class toeVoegKnopHandler implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			String cat = naamCategorie.getText();
			String resultaat = ciiBay.categorieToevoegen(cat);
			if(!resultaat.equals("Categorie toegevoegd!")){
				JOptionPane.showMessageDialog(null, resultaat, "Fout!", JOptionPane.ERROR_MESSAGE);
			}else{
				JOptionPane.showMessageDialog(null, resultaat, "Gelukt!", JOptionPane.INFORMATION_MESSAGE);
			}
		}
	}	
}
